import axios from 'axios'
import { ElMessage } from "element-plus";
export default axios.create({
   baseURL: 'https://music-three-phi.vercel.app',
   // withCredentials: true,
   timeout: 5000,
   params: {
      realIP: '192.168.0.119',

   },
   transformResponse: [function (data) {

      // 对 data 进行任意转换处理
      const state = JSON.parse(data);

      switch (state.code) {
         case 403:
            ElMessage({
               message: "无权限",
               offset: 100,
               appendTo: document.querySelector("#tip"),
            });
            break;
         case 401:

            ElMessage({
               message: "未登录",
               offset: 100,
               appendTo: document.querySelector("#tip"),
            });
            break;
         case 404:
            ElMessage({
               message: "没有找到资源",
               offset: 100,
               appendTo: document.querySelector("#tip"),
            });
            break;
         case 503:
            ElMessage({
               message: "服务器繁忙",
               offset: 100,
               appendTo: document.querySelector("#tip"),
            });

            break;
         default:
            break;
      }
      return state;
   }],
})






